home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / archiver / lzhtv12.zip / CINPUT.PAS next >
Pascal/Delphi Source File  |  1990-04-22  |  12KB  |  506 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1990 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. {$i prodef.inc}
  14.  
  15. {$D+}    {Global debug information}
  16. {$L+}    {Local debug information}
  17.  
  18. unit CInput;
  19.  
  20. interface
  21.  
  22.    Uses
  23.       Dos, MiniCrt, Mdosio, Tools;
  24.  
  25.    var
  26.       linenum:       integer;
  27.       pending_keys:  string;
  28.       cmdline:       string;
  29.       par:           string;
  30.       ontime:        integer;
  31.       tleft:         integer;
  32.  
  33.    const
  34.       tlimit:  integer = 10;  {default time limit}
  35.       allow_flagging = false;
  36.       graphics = false;
  37.       red = '';
  38.       green = '';
  39.       yellow = '';
  40.       blue = '';
  41.       magenta = '';
  42.       cyan = '';
  43.       white = '';
  44.       gray = '';
  45.       fun_arcview = 'V';
  46.       fun_textview = 'T';
  47.       fun_xtract = 'X';
  48.       enter_eq = '(Enter)=';
  49.       option = '';
  50.       expert = true;
  51.       dump_user: boolean = false;
  52.  
  53.    type
  54.       user_rec = record
  55.            pagelen: integer;
  56.       end;
  57.  
  58.    const
  59.       user: user_rec = (pagelen:22);
  60.       o_logoff = 'x';
  61.       o_offok = 'x';
  62.       o_offerr = 'x';
  63.  
  64.    const
  65.       queue_size       =  300;   {fixed size of all queues}
  66.       queue_high_water =  255;   {maximum queue.count before blocking}
  67.       queue_low_water  =  100;   {unblock queue at this point}
  68.  
  69.    type
  70.       queue_rec = record
  71.          next_in:  integer;
  72.          next_out: integer;
  73.          count:    integer;
  74.          data:     array[1..queue_size] of char;
  75.       end;
  76.  
  77.    {$i intrcomm.int}
  78.  
  79.    procedure opencom(port: integer);
  80.    procedure closecom;
  81.    function local: boolean;
  82.    function carrier_present: boolean;
  83.  
  84.    procedure disp(msg:  string);
  85.    procedure newline;
  86.    procedure displn(msg:  string);
  87.    procedure space;
  88.    procedure spaces(n: integer);
  89.    procedure input(var line:  string; maxlen:    integer);
  90.    procedure prompt_def(what,options: string);
  91.    procedure get_def(what,options: string);
  92.    procedure get_cmdline_raw(len: integer);
  93.  
  94. (*******
  95.    procedure dRED(m: string);
  96.    procedure dGREEN(m: string);
  97.    procedure dYELLOW(m: string);
  98.    procedure dBLUE(m: string);
  99.    procedure dMAGENTA(m: string);
  100.    procedure dCYAN(m: string);
  101.    procedure dWHITE(m: string);
  102.    procedure dGRAY(m: string);
  103.    procedure default_color;
  104. ******)
  105.  
  106.    procedure get_cmdline;
  107.    function scan_nextpar(var cmdline: string): string;
  108.    procedure get_nextpar;
  109.  
  110.    function verify_level(fun: char): boolean;
  111.    procedure set_function(fun: char);
  112.    procedure erase_prompt(len: integer);
  113.    procedure check_time_left;
  114.    procedure display_time(left: boolean);
  115.    procedure flag_files;
  116.    procedure make_log_entry(s:string; f:boolean);
  117.    function nomore: boolean;
  118.  
  119.  
  120. (* ------------------------------------------------------------ *)
  121. implementation
  122.  
  123.    procedure flush_com;
  124.    begin
  125.       INTR_flush_com;
  126.    end;
  127.  
  128.    {$i intrcomm.inc}
  129.  
  130.    function local: boolean;
  131.    begin
  132.       local := (com_chan = 0);
  133.    end;
  134.  
  135.    procedure opencom(port: integer);
  136.    begin
  137.       if (port > 0) and (port <= MAX_COMn) then
  138.       begin
  139.          com_chan := port;
  140.          INTR_init_com;
  141.          if not carrier_present then
  142.          begin
  143.             closecom;
  144.             com_chan := 0;
  145.          end;
  146.       end;
  147.    end;
  148.  
  149.    procedure closecom;
  150.    begin
  151.       if not local then
  152.          INTR_uninit_com;
  153.    end;
  154.  
  155.  
  156.    (* ------------------------------------------------------------ *)
  157.    procedure get_cmdline;
  158.       (* read next command line *)
  159.    var
  160.       i: integer;
  161.  
  162.    begin
  163.       fillchar(cmdline,sizeof(cmdline),0);
  164.       input(cmdline,sizeof(cmdline)-1);
  165.       stoupper(cmdline);
  166.       newline;
  167.  
  168.       {process stacked 'ns' at end of command line}
  169.       i := pos(' NS',cmdline);
  170.       if i = 0 then
  171.          i := pos(';NS',cmdline);
  172.  
  173.       if (i > 0) and (i = length(cmdline)-2) then
  174.       begin
  175.          cmdline[0] := chr(i-1);
  176.          linenum := -30000;    {go 30000 lines before stopping again}
  177.       end;
  178.    end;
  179.  
  180.  
  181.    (* ------------------------------------------------------------ *)
  182.    function scan_nextpar(var cmdline: string): string;
  183.       (* get the next space or ';' delimited part of a command line
  184.          and return it (removing the string from the command line) *)
  185.    var
  186.       i:      integer;
  187.       par:    string;
  188.  
  189.    begin
  190.       fillchar(par,sizeof(par),0);
  191.       while copy(cmdline,1,1) = ' ' do   {remove leading spaces}
  192.          delete(cmdline,1,1);
  193.  
  194.       (* find the end of the next word *)
  195.       i := 1;
  196.       while (i <= length(cmdline)) and (cmdline[i] <> ' ') and
  197.             (cmdline[i] <> ';') and (cmdline[i] <> ',') do
  198.          inc(i);
  199.  
  200.       (* copy the word to the next param and delete it from the command line *)
  201.       par := copy(cmdline,1,i-1);
  202.       delete(cmdline,1,i);
  203.  
  204.       scan_nextpar := par;
  205.    end;
  206.  
  207.  
  208.    (* ------------------------------------------------------------ *)
  209.    procedure get_nextpar;
  210.       (* get the next space or ';' delimited part of the command line
  211.          and move it to 'par' *)
  212.    begin
  213.       fillchar(par,sizeof(par),0);
  214.       par := scan_nextpar(cmdline);
  215.    end;
  216.  
  217.  
  218.    (* ------------------------------------------------------------ *)
  219.    function carrier_present: boolean;
  220.    begin
  221.       carrier_present := (port[port_base+MSR] and MSR_RLSD) <> 0;
  222.    end;
  223.  
  224.    procedure check_carrier;
  225.    begin
  226.       if (not carrier_present) and (not dump_user) then
  227.       begin
  228.          dump_user := true;
  229.          displn(^M^J'Carrier lost!');
  230.       end;
  231.    end;
  232.  
  233.  
  234.    (* ------------------------------------------------------------ *)
  235.    procedure disp(msg:  string);
  236.    begin
  237.       write(msg);
  238.       if not local then
  239.       begin
  240.          INTR_transmit_data(msg);
  241.          check_carrier;
  242.       end;
  243.    end;
  244.  
  245.  
  246.    (* ------------------------------------------------------------ *)
  247.    procedure newline;
  248.    var
  249.       c: char;
  250.  
  251.    begin
  252. {WRITE('`1');}
  253.       verify_txque_space;
  254. {WRITE('`2');}
  255.       disp(^M^J);
  256.       inc(linenum);
  257.  
  258.       if keypressed then
  259.       begin
  260.          c := readkey;
  261.          if (c = ^K) then
  262.          begin
  263.             disable_int;
  264.             control_k;
  265.             enable_int;
  266.          end
  267.          else
  268.  
  269.          if c <> carrier_lost then
  270.          begin
  271.             inc(pending_keys[0]);
  272.             pending_keys[length(pending_keys)] := c;
  273.          end;
  274.       end;
  275.    end;
  276.  
  277.    procedure displn(msg:  string);
  278.    begin
  279.       disp(msg);
  280.       newline;
  281.    end;
  282.  
  283.    procedure dispc(c: char);
  284.    begin
  285.       disp(c);
  286.    end;
  287.  
  288.    procedure space;
  289.    begin
  290.       dispc(' ');
  291.    end;
  292.  
  293.  
  294.    (* ------------------------------------------------------------ *)
  295.    procedure spaces(n: integer);
  296.    begin
  297.       while n > 0 do
  298.       begin
  299.          space;
  300.          dec(n);
  301.       end;
  302.    end;
  303.  
  304.  
  305.    (* ------------------------------------------------------------ *)
  306.    procedure input(var line:  string;
  307.                    maxlen:    integer);
  308.    var
  309.       c:     char;
  310.  
  311.    begin
  312.       linenum := 1;
  313.       line := '';
  314.  
  315.       repeat
  316.          c := #0;
  317.  
  318.          while (c = #0) and (not dump_user) do
  319.          begin
  320.             check_time_left;
  321.  
  322.             if length(pending_keys) > 0 then
  323.             begin
  324.                c := pending_keys[1];
  325.                delete(pending_keys,1,1);
  326.             end;
  327.  
  328.             if keypressed then
  329.                c := readkey;
  330.  
  331.             if (not local) then
  332.             begin
  333.                check_carrier;
  334.                if INTR_receive_ready then
  335.                   c := INTR_receive_data;
  336.             end;
  337.  
  338.             if c = #0 then
  339.                give_up_time;
  340.          end;
  341.  
  342.          if dump_user then
  343.          begin
  344.             line := carrier_lost;
  345.             exit;
  346.          end;
  347.  
  348.